import 'package:dio/dio.dart';
import 'package:flutter_changdian_football/api/api.dart';
import 'package:flutter_changdian_football/api/api_response.dart';
import 'package:flutter_changdian_football/api/http_utils.dart';
import 'package:flutter_changdian_football/global.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:package_info_plus/package_info_plus.dart';

class ReqOther {

  /// 获取静态资源URL
  static Future<ApiResponse<dynamic>> getProtocol(String fileType) async {
    try {
      var response = await HttpUtils.post(Api.getProtocol, data: {
        'fileType': fileType
      });
      return ApiResponse.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    } finally {
      EasyLoading.dismiss();
    }
  }

  /// 用户帮助问答列表
  static Future<ApiResponse<dynamic>> helpQuestion() async {
    try {
      var response = await HttpUtils.get(Api.helpQuestion);
      return ApiResponse.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    } finally {
      EasyLoading.dismiss();
    }
  }

  /// 文件上传接口
  static Future<ApiResponse<dynamic>> fileUpload(FormData formData) async {
    try {
      var response = await HttpUtils.post(Api.fileUpload, data: formData);
      return ApiResponse.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    } finally {
      EasyLoading.dismiss();
    }
  }
  
  /// 用户意见反馈
  static Future<ApiResponse<dynamic>> userAdvice(
    {
      String? adviceType,
      String? adviceContent,
      String? firstImgUrl,
      String? secondImgUrl,
      String? thirdImgUrl
    }
  ) async {
    try {
      var response = await HttpUtils.post(Api.userAdvice, data: {
        'adviceType': adviceType,
        'adviceContent': adviceContent,
        "firstImgUrl": firstImgUrl,
        "secondImgUrl": secondImgUrl,
        "thirdImgUrl": thirdImgUrl,
      });
      return ApiResponse.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    } finally {
      EasyLoading.dismiss();
    }
  }

  /// 用户消息通知设置 - 查看
  static Future<ApiResponse<dynamic>> getUserNotifySetting() async {
    try {
      var response = await HttpUtils.get(Api.getUserNotifySetting);
      return ApiResponse.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    } finally {
      EasyLoading.dismiss();
    }
  }

  /// 用户消息通知设置 - 设置
  static Future<ApiResponse<dynamic>> userNotifySet(
    {
      String? allSwitch,
      String? clubCheckNotify,
      String? clubDynamicNotify,
      String? interestNotify,
      String? matchNotify,
      String? praiseNotify,
      String? systemNotify
    }
  ) async {
    try {
      var response = await HttpUtils.post(Api.userNotifySet, data: {
        "allSwitch": allSwitch,
        "clubCheckNotify": clubCheckNotify,
        "clubDynamicNotify": clubDynamicNotify,
        "interestNotify": interestNotify,
        "matchNotify": matchNotify,
        "praiseNotify": praiseNotify,
        "systemNotify": systemNotify
      });
      return ApiResponse.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    } finally {
      EasyLoading.dismiss();
    }
  }

  /// 检查更新
  static Future<ApiResponse<dynamic>> versionCheck() async {
    try {
      PackageInfo packageInfo = await PackageInfo.fromPlatform();
      String version = packageInfo.version;
      var response = await HttpUtils.post(Api.versionCheck, data: {
        "appName": 'changdian-football',
        "version": version
      });
      return ApiResponse.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    } finally {
      EasyLoading.dismiss();
    }
  }

  /// 注销账户
  static Future<ApiResponse<dynamic>> accountCancellation() async {
    try {
      var response = await HttpUtils.get(Api.accountCancellation);
      return ApiResponse.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    } finally {
      EasyLoading.dismiss();
    }
  }

  /// 获取页面分享信息
  static Future<ApiResponse<dynamic>> getSharePage({
    String? clubId,
    String? matchId,
    required String sharePageName,
    String? userId
  }) async {
    try {
      var response = await HttpUtils.post(Api.getSharePage, data: {
        'clubId': clubId,
        'matchId': matchId,
        'sharePageName': sharePageName,
        'userId': userId
      });
      return ApiResponse.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    } finally {
      EasyLoading.dismiss();
    }
  }

  /// 获取俱乐部默认头像列表
  static Future<ApiResponse<dynamic>> defaultClubAvatar() async {
    try {
      var response = await HttpUtils.get(Api.defaultClubAvatar);
      return ApiResponse.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    } finally {
      EasyLoading.dismiss();
    }
  }

  /// 首页基本数据信息 轮播图 功能栏图标 用户未读消息数
  static Future<ApiResponse<dynamic>> indexPageBaseInfo() async {
    try {
      var response = await HttpUtils.get(Api.indexPageBaseInfo);
      return ApiResponse.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    } finally {
      EasyLoading.dismiss();
    }
  }
  
  /// 新闻列表
  static Future<ApiResponse<dynamic>> newsList(
    {
      int pageNum = 1
    }
  ) async {
    try {
      var response = await HttpUtils.post(Api.newsList, data: {
        'pageNum': pageNum,
        'pageSize': Global.pageSize
      });
      return ApiResponse.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    } finally {
      EasyLoading.dismiss();
    }
  }

  /// 首页 - 新闻列表 - 新闻内容
  static Future<ApiResponse<dynamic>> newsContent(
    {
      String? newsId
    }
  ) async {
    try {
      var response = await HttpUtils.post(Api.newsContent, data: {
        'newsId': newsId,
      });
      return ApiResponse.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    } finally {
      EasyLoading.dismiss();
    }
  }

  /// 设置用户手机deviceToken
  static Future<ApiResponse<dynamic>> setDeviceToken(
    {
      String? deviceToken
    }
  ) async {
    try {
      var response = await HttpUtils.post(Api.setDeviceToken, data: {
        'deviceToken': deviceToken,
      });
      return ApiResponse.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    } finally {
      EasyLoading.dismiss();
    }
  }

  /// 获取用户消息列表
  static Future<ApiResponse<dynamic>> userMessageList(
    {
      int pageNum = 1
    }
  ) async {
    try {
      var response = await HttpUtils.post(Api.userMessageList, data: {
        'pageNum': pageNum,
        'pageSize': Global.pageSize
      });
      return ApiResponse.completed(response);
    } on DioError catch (e) {
      return ApiResponse.error(e.error);
    } finally {
      EasyLoading.dismiss();
    }
  }
}